import 'package:cached_network_image/cached_network_image.dart';
import 'package:imember/Util/Global.dart';
import 'package:imember/Util/HttpGo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class LocalImage extends StatelessWidget {
  LocalImage(this.path, {this.onTap, this.width, this.height, this.padding, this.bgColor, this.fit});

  String path = "";
  void Function()? onTap;
  EdgeInsetsGeometry? padding;
  double? width;
  double? height;
  Color? bgColor;
  BoxFit? fit;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: onTap,
        behavior: HitTestBehavior.opaque,
        child: Container(
            decoration: BoxDecoration(color: bgColor),
            padding: padding ?? EdgeInsets.all(0),
            child: Image(
              image: AssetImage("images/" + path),
              width: width,
              height: height,
              fit: fit,
            )));
  }
}

class NetImage extends StatelessWidget {
  NetImage(this.url, {this.onTap, this.width, this.height, this.padding, this.fit, this.radius});

  String url = "";
  void Function()? onTap;
  EdgeInsetsGeometry? padding;
  double? width;
  double? height;
  BoxFit? fit;
  double? radius;

  @override
  Widget build(BuildContext context) {
    if (!url.startsWith("http")) {
      url = HttpGo.DO_MAIN + url;
    }
    return GestureDetector(
        onTap: onTap,
        behavior: HitTestBehavior.opaque,
        child: Padding(
          padding: padding ?? EdgeInsets.all(0),
          child: ClipRRect(
            borderRadius: BorderRadius.circular(radius ?? 0),
            child: CachedNetworkImage(
              imageUrl: url,
              width: width,
              height: height,
              fit: fit,
            ),
          ),
        ));
  }
}
